package com.yy.wga.admin.service.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yy.wga.mp.common.interceptor.RequestUserHolder;
import com.yy.wga.mp.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.module.admin.request.AdminMerchantPromotePosterSaveRequest;
import com.yy.wga.mp.module.admin.response.AdminMerchantPromotePosterInfoResponse;
import com.yy.wga.mp.module.merchant.entity.pojo.MerchantPromotePosterDO;
import com.yy.wga.mp.module.merchant.service.MerchantPromotePosterService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 运营后台/推广海报
 *
 * @author guochao
 * @since 2024-11-10 21:11:05
 */
@RestController
@RequestMapping("admin/merchant/promotePoster")
public class AdminMerchantPromotePosterController {
    /**
     * 服务对象
     */
    @Resource
    private MerchantPromotePosterService merchantPromotePosterService;

    /**
     * 查询
     * @return
     */
    @GetMapping("get")
    public Result<AdminMerchantPromotePosterInfoResponse> get() {
        MerchantPromotePosterDO promotePoster = merchantPromotePosterService.getOne(new LambdaQueryWrapper<MerchantPromotePosterDO>()
                .eq(MerchantPromotePosterDO::getAppKey, RequestUserHolder.getBaseRequest().getAppKey()));
        return Result.success(BeansUtils.map(promotePoster, AdminMerchantPromotePosterInfoResponse.class));
    }

    /**
     * 保存
     * @param request
     * @return
     */
    @PostMapping("save")
    public Result<Boolean> save(@Valid @RequestBody AdminMerchantPromotePosterSaveRequest request) {
        MerchantPromotePosterDO promotePoster = BeansUtils.map(request, MerchantPromotePosterDO.class);
        promotePoster.setAppKey(RequestUserHolder.getBaseRequest().getAppKey());
        merchantPromotePosterService.saveOrUpdate(promotePoster);
        return Result.success(Boolean.TRUE);
    }
}
